<%--
  Created by IntelliJ IDEA.
  User: Mac
  Date: 2020/12/24
  Time: 10:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%String path = request.getContextPath()+"/";%>
<!DOCTYPE html>
<html>
<head>
    <base href="<%=path%>">
    <meta charset="utf-8">
    <title>用户新增</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="layui/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="//at.alicdn.com/t/font_tnyc012u2rlwstt9.css" media="all" />
    <link rel="stylesheet" href="layui/css/user.css" media="all" />
    <style type="text/css">
        .layui-form-item .layui-inline{ width:33.333%; float:left; margin-right:0; }
        @media(max-width:1240px){
            .layui-form-item .layui-inline{ width:100%; float:none; }
        }
    </style>
</head>
<body class="childrenBody">
<form class="layui-form" style="width:80%;" id="form1">
    <input type="hidden" name="id" value="${user.id}"/>
    <div class="layui-form-item">
        <label class="layui-form-label">登录名</label>
        <div class="layui-input-block">
            <input type="text" name="loginAccount" value="${user.loginAccount}" class="layui-input userName" lay-verify="required" placeholder="请输入登录名">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="password" name="pwd" value="${user.pwd}" class="layui-input userEmail" lay-verify="required" placeholder="请输入邮箱">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="realName" value="${user.realName}" class="layui-input userEmail"  placeholder="请输入邮箱">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系电话</label>
        <div class="layui-input-block">
            <input type="text" name="phone" value="${user.phone}" class="layui-input userEmail" lay-verify="phone" placeholder="请输入邮箱">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block userSex">
                <input type="radio" name="sex" value="0" title="男" <c:if test="${user.sex!=1}">checked</c:if>/>
                <input type="radio" name="sex" value="1" title="女" <c:if test="${user.sex==1}">checked</c:if>>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所属部门</label>
        <div class="layui-input-block">
            <select name="sOId" lay-filter="aihao">
                <c:forEach items="${orgs}" var="org">
                    <option value="${org.id}" <c:if test="${org.id==user.sOId}">selected</c:if>>${org.orgName}</option>
                </c:forEach>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所属角色</label>
        <div class="layui-input-block">
            <select name="roleid" lay-filter="aihao">
                <c:forEach items="${roles}" var="role">
                    <option value="${role.id}" <c:if test="${role.id==user.roleid}">selected</c:if>>${role.roleName}</option>
                </c:forEach>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <c:set var="status" value="1"></c:set>
            <c:if test="${not empty user}">
                <c:set var="status" value="${user.status}"/>
            </c:if>
            <input type="hidden" name="status" value="${status}" id="status"/>
            <input type="checkbox" name="switch"  lay-filter="status"  lay-text="启用|停用" checked lay-skin="switch">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn submit" lay-submit="" lay-filter="addUser" type="button">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="layui/layui/layui.js"></script>
<script type="text/javascript">
    layui.config({
        base : "js/"
    }).use(['form','layer','laypage','jquery'],function() {
        form = layui.form();
        $=layui.jquery;
        $(".submit").click(function(){
            //
            var param = $("#form1").serialize();
            $.ajax({
                url:'user/save',
                type:'post',
                dataType:'json',
                data:param,
                success:function(ret){
                    if(ret.status){
                      layui.layer.msg("保存成功!",function(){
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                          parent.location.reload();
                          parent.layer.close(index); //再执行关闭
                      });
                    }else{
                        layui.layer.msg('保存失败！');
                    }
                }
            })
        });
        form.on('switch(status)', function(data){
            console.log(data.elem); //得到checkbox原始DOM对象
            var obj = data.elem;
            if(data.elem.checked){
                $("#status").val('1');
            }else{
                $("#status").val("0");
            }
        });
    });
</script>
</body>
</html>
